package game.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;

/**
 *
 * @author Gab'z
 */
public class PanelBlack extends JPanel {

    private static PanelBlack blackPanel = null;
    private static Integer alpha = 0;

    public static PanelBlack getPanelBlack() {

        blackPanel = new PanelBlack();

        return blackPanel;
    }

    private PanelBlack() {
        //super(Frame.getFrame());
        //On place le JDialog au centre de l'écran
        // setLocationRelativeTo(Frame.getFrame());

        //On désactive la barre de titre
        // setUndecorated(true);
        //On est organisés alors on place tout les les éléments voulus dans un panel
        //On choisit un GridLayout de 1 ligne sur 1 colonne, on se complique pas pour l'exemple !
        this.setLayout(new BorderLayout());
        this.setSize(980, 810);
        //panel.setLocation(0, 0);
        // panel.setLocation(PanelJeu.getPanelJeu().getLocation());
        this.setBackground(new Color(0, 0, 0, 0));
        this.setOpaque(false);


        // this.setLocation(PanelJeu.getPanelJeu().getLocation());
        this.setVisible(true);
        //pack();
        //On crée notre Timer
        //  Timer timer = new Timer();
        //Et on lance le fade-out, on attend 500 ms avant de commencer à estomper
        //Puis on estompe un peu plus toutes les 5ms
        //timer.schedule(new FadeOut(this), 5000, 50);
        //timer.schedule(new FadeIn(this), 5000, 50);
    }

   public static void resetPanelBlack() {
        blackPanel = null;
        alpha = 0;
    }

    public void increaseAlpha() {
        alpha++;
        paintComponent(this.getGraphics());
    }

    public void decreaseAlpha() {
        alpha--;
        paintComponent(this.getGraphics());
        //this.setBackground(new Color(0, 0, 0, this.getBackground().getAlpha() - 1));
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Color ppColor = new Color(0, 0, 0, alpha); //r,g,b,alpha
        g.setColor(ppColor);
        g.fillRect(0, 0, 980, 810); //x,y,width,height


    }

    Integer getAlpha() {
        return alpha;
    }
}
